#include "LxPThreadAux.h"

timespec pthread_stoptime(unsigned int dwMilliseconds)
{
	if (dwMilliseconds == INFINITE)
		return {0, 0};
		
    timespec ts;
    clock_gettime(CLOCK_REALTIME, &ts);
    return pthread_stoptime(ts, dwMilliseconds);
}

timespec pthread_stoptime(timespec &ts, unsigned int dwMilliseconds)
{
    timespec tsTemp = ts;
    tsTemp.tv_sec += dwMilliseconds / 1000;
    tsTemp.tv_nsec += (dwMilliseconds % 1000) * 1000000;
    if (tsTemp.tv_nsec >= 1000000000)
    {
        tsTemp.tv_sec += 1;
        tsTemp.tv_nsec -= 1000000000;
    }

    return tsTemp;
}
